﻿Imports System
Imports System.Collections
Imports System.ComponentModel.Design
Imports System.Windows.Forms

Namespace System.Workflow.ComponentModel.Design
    Friend NotInheritable Class DragSelectionMessageFilter
        Inherits DragRectangleMessageFilter
        ' Methods
        Friend Sub New()
        End Sub

        Protected Overrides Function OnKeyUp(ByVal eventArgs As KeyEventArgs) As Boolean
            MyBase.OnKeyUp(eventArgs)
            If ((Control.ModifierKeys And Keys.Shift) = Keys.None) Then
                MyBase.DragStarted = False
            End If
            Return False
        End Function

        Protected Overrides Function OnMouseDown(ByVal eventArgs As MouseEventArgs) As Boolean
            If ((Control.ModifierKeys And Keys.Shift) > Keys.None) Then
                MyBase.OnMouseDown(eventArgs)
                Return True
            End If
            Return False
        End Function

        Protected Overrides Function OnMouseMove(ByVal eventArgs As MouseEventArgs) As Boolean
            If ((Control.ModifierKeys And Keys.Shift) > Keys.None) Then
                MyBase.OnMouseMove(eventArgs)
                Return True
            End If
            Return False
        End Function

        Protected Overrides Function OnMouseUp(ByVal eventArgs As MouseEventArgs) As Boolean
            If ((Control.ModifierKeys And Keys.Shift) <= Keys.None) Then
                Return False
            End If
            MyBase.OnMouseUp(eventArgs)
            Dim parentView As WorkflowView = MyBase.ParentView
            If (Not MyBase.DragRectangle.IsEmpty AndAlso (Not parentView.RootDesigner Is Nothing)) Then
                Dim intersectingDesigners As ActivityDesigner() = CompositeActivityDesigner.GetIntersectingDesigners(parentView.RootDesigner, MyBase.DragRectangle)
                Dim list As New ArrayList
                Dim designer As ActivityDesigner
                For Each designer In intersectingDesigners
                    list.Add(designer.Activity)
                Next
                Dim service As ISelectionService = [TryCast](MyBase.GetService(GetType(ISelectionService)),ISelectionService)
                If ((list.Count > 0) AndAlso (Not service Is Nothing)) Then
                    service.SetSelectedComponents(DirectCast(list.ToArray(GetType(Object)), Object()), SelectionTypes.Replace)
                End If
            End If
            Return True
        End Function

    End Class
End Namespace

